import { defineStore } from "pinia";
import axios from "axios";
import type { CategoryState } from "../../types/Category/type";

let useCategoryStore = defineStore('Category', {
    state: () : CategoryState => {
        return{
          firstClass: [] ,
          //存储一级分类的id
          c1Id: '',
          secondClass: [],
          c2Id: '',
          thirdClass: [],
          c3Id: '',
          tableData: []
        }
    },
    actions: {
      //获取一级分类的方法 
      async getC1(){
        await axios({
           //url: 'http://sph-api.atguigu.cn/admin/product/getCategory1',
           url: 'http://127.0.0.1:4523/m1/5379113-5051715-default/getCategory1',
           method: 'GET'
        }).then((response) => {
            console.log('仓库',response.data)
            this.firstClass = response.data.data 
        })
      },
      async getC2(id: string | number){
        await axios({
          //url: 'http://sph-api.atguigu.cn/admin/product/getCategory2/'+`${id}`,
          url: 'http://127.0.0.1:4523/m1/5379113-5051715-default/getCategory2/'+`${id}`,
          method: 'GET'
        }).then((response) => {
             console.log('仓库请求二',response.data)
             this.secondClass = response.data.data 
        })
      },
      async getC3(id: number | string){
        await axios({
          //url: 'http://sph-api.atguigu.cn/admin/product/getCategory3/'+`${id}`,
          url: 'http://127.0.0.1:4523/m1/5379113-5051715-default/getCategory3/'+`${id}`,
          method: 'GET'
        }).then((response) => {
            console.log('仓库请求三',response.data)
            this.thirdClass = response.data.data
        })
      },
      //获取表格属性的数据
      async getTable(id1: number | string, id2: number | string, id3: number | string){
        await axios({
          //url: 'http://sph-api.atguigu.cn/admin/product/getCategory1/getCategory2/getCategory3/'+`${id1}/${id2}/${id3}`,
          url: 'http://127.0.0.1:4523/m1/5379113-5051715-default/getCategory1/getCategory2/getCategory3/'+`${id1}/${id2}/${id3}`,
          method: 'GET'
        }).then((response) => {
            this.tableData = response.data.data
        })
      }
    },
    getters: {
        
    }
})

export default useCategoryStore